<?
	  include("/inc/header.html") {}
    ?> 
     <link rel="stylesheet" href="static/zTree_v3/css/demo.css" type="text/css"></link>
    <link rel="stylesheet" href="static/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css"></link>
	<script type="text/javascript" src="static/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
    <style>
    	.tapqh{
    		height:35px;
    		margin:0px;
    		margin-top:5px;
    		padding:0px;
    		border-bottom:3px solid #d74b47;
    	}
    	.tapqh li{
    		float:left;
    		list-style: none;
    		line-height:33px;
    	}
    	.tapqh li a{
    		display:inline-block;
    		padding: 0px 15px;
    		font-size: 16px;
    		color: #333;
    		text-decoration: none;
    	}
    	.tapqh li a:hover{
    		color: #d74b47;
    		background-color: transparent;
    	}
    	.tapqh li a.active{
    		background-color:#d74b47;
    		color:#ffffff;
    	}
    </style>
	<div class="row">
		<div  class="col-md-12" style="width: 100%; " >
		<ul class="tapqh js-tapqh">
			<li><a href="JavaScript:;" class="active">基本信息</a></li>
			<li><a href="JavaScript:;">参照项</a></li>
			<li><a href="JavaScript:;">层级关系</a></li>			
		</ul>
		</div>
		<div class="js-tapbox">
			<div  class="col-md-12" style="width: 100%; display: none;">
	        		<div class="panel" >
					<div class="panel-body pan " style="width:auto;height:480px;overflow: auto;">
						<form action="#" class="form-horizontal">
							<div class="form-body pal"
								style="float:left;width:100%; overflow: auto;">
								<input id="id" type="hidden" class="form-control" />

								<div style="margin-top:-10px;  padding-bottom: 5px;">
									<label for="wordName" class="col-md-4 control-label">
										<div align="right">
											主题款目词<span class='require' >*</span>
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<input id="wordName" type="text" class="form-control" />
										</div>
									</div>
								</div>
								
								<div style="padding-bottom: 5px;">
									<label for="wordFormal" class="col-md-3 control-label">词表分类
										<span class='require'>*</span> </label>
									<div class="col-md-9">
										<div class="input-icon">
											<select id="wordClasses" class="form-control">
												<?for(twm in thesauriWordModule){?>
													<option value="${twm.id}">${twm.nameZh}</option>
												<?}?>
											</select>
										</div>
									</div>
								</div>
								
								<div id="topTermXia" style="padding-bottom: 5px;">
									<label for="isTopTerm" class="col-md-3 control-label">是否族首词
										<span class='require'>*</span> </label>
									<div class="col-md-9">
										<div class="input-icon">
											<select id="isTopTerm" class="form-control">
												<option value="0">false</option>
												<option value="1">true</option>
											</select>
										</div>
									</div>
								</div>
								<div style="padding-bottom: 5px;">
									<label for="wordFormal" class="col-md-3 control-label">是否正式主题词
										<span class='require'>*</span> </label>
									<div class="col-md-9">
										<div class="input-icon">
											<select id="wordFormal" class="form-control">
												<option value="0">true</option>
												<option value="1">false</option>
											</select>
										</div>
									</div>
								</div>

								<div style="padding-bottom: 5px;">
									<label for="wordPinyin" class="col-md-4 control-label">
										<div align="right">
											汉语拼音 
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<input id="wordPinyin" type="text" class="form-control" onchange="verify(this.value,this.id);" />
										</div>
									</div>
								</div>

								<div style="padding-bottom: 5px;">
									<label for="wordEnglish" class="col-md-4 control-label">
										<div align="right">
											英文译名 
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<input id="wordEnglish" type="text" class="form-control" onchange="verify(this.value,this.id);" />
										</div>
									</div>
								</div>
								
								
								<div style="padding-bottom: 5px;">
										<label for="thesauriWordCategoryName" class="col-md-3 control-label">
											<div align="right">范畴名称<span class='require' >*</span></div>
											</label>
										<div class="col-md-9">
											<div class="input-group input-group-sm mbs">
												<input id="thesauriWordCategoryName" type="text" placeholder="请选择"
													class="form-control" disabled="true" /> <span
													class="input-group-btn"><button id="xuanze"
														onclick="saveEditZTree()" type="button"
														data-toggle="dropdown"
														class="btn btn-success dropdown-toggle">选择类..</button>
												</span>
											</div>
										</div>
								</div>
								<input id="thesauriWordCategoryId" type="hidden" class="form-control" />
								
								<div style="padding-bottom: 5px;">
									<label for="scopeNote" class="col-md-4 control-label">
										<div align="right">
											含义注释 <span class='require' ></span>
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<textarea id="scopeNote"  rows="3" cols="20" class="form-control" ></textarea> 
										</div>
									</div>
								</div>
								
								<div style="padding-bottom: 5px;">
									<label for="usageNote" class="col-md-4 control-label">
										<div align="right">
											用法注释 <span class='require'></span>
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<textarea id="usageNote"  rows="3" cols="20" class="form-control" ></textarea> 
										</div>
									</div>
								</div>
								
								<div style="padding-bottom: 0px;">
									<label for="historicalNote" class="col-md-4 control-label">
										<div align="right">
										     历史注释 <span class='require'></span>
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<textarea id="historicalNote"  rows="3" cols="20" class="form-control" ></textarea> 
										</div>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div>
	        </div>
	        <div  class="col-md-12" style="width: 100%; display: none;" >
	        	<div class="panel" style="height: auto;overflow: auto; ">
	                <div class="panel-body" style="height: 624px;overflow: auto;">
	                	<div  class="row">
	                		<input type="hidden" value="${relation}" id="relation" name="relation"/>
	                		  <table class="table table-hover table-bordered">
	                		  		<?for(twrl in thesauriWordRelationLsit){?>
	                		  			<tr>
	                                     	<td width="10%" align="center"><h5>${twrl.nameZh}(${twrl.nameEn})：</h5></td>
	                                     	<td ><div id="center_${twrl.nameEn}" style="height:100px;overflow: auto;"></div></td>
                                     	</tr>
	                		  		<?}?>
                              </table>
	                     </div>
	                 </div>
	            </div>
	        </div>
	        <div  class="col-md-12" style="width: 100%; display: none;">
	        	<div class="panel" >
					<div class="panel-body pan " style="width:auto;height:380px;overflow: auto;">
						<div id="upWord" style="display: none;"></div>
						<div id="treeDemo" class="ztree" style="margin-left: 35px;;width:340px;" >
					    </div>
					</div>
				</div>
	        </div>
		</div>
</div>

<script type="text/javascript">
var thesauriWordId = window.parent.getthesauriWordId2();
var relevanceCurr = window.parent.getRelevanceCurr();
var addwordClasses;
	$(function() {
		findEditThesauriWordReference();
		demo();
		upWord();
	});
	
	//基本信息
	function demo() {
		$.getJSON('./thesauriWordEditShow.do', {
			id : thesauriWordId,
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#wordName").val(res[0].wordName);
			$("#isTopTerm").val(res[0].isTopTerm);
			selected("wordClasses",res[0].thesauriWordModuleId);
			$("#wordPinyin").val(res[0].wordPinyin);
			$("#wordEnglish").val(res[0].wordEnglish);
			$("#thesauriWordCategoryName").val(res[0].thesauriWordCategoryName);
			$("#thesauriWordCategoryId").val(res[0].thesauriWordCategoryId);
			$("#scopeNote").val(res[0].scopeNote);
			$("#usageNote").val(res[0].usageNote);
			$("#historicalNote").val(res[0].historicalNote);
			$("#wordFormal").val(res[0].wordFormal);
			addwordClasses=res[0].thesauriWordModuleId;
		});
	};
	
	function selected(selectname, selectid) {
		$("#" + selectname + " option").each(function() { //遍历全部option
			var v = $(this).val(); //获取option的内容
			if (v == selectid) {
				$(this).attr("selected", "selected");
			}
		});
	}
	function Page() {
		if($.trim($("#wordName").val()).length<1) {
        	alert('词名称不能为空！');
        	return null;
        }
        if($.trim($("#isTopTerm").val())==-1) {
        	alert('请选择是或否！');
        	return null;
        }
        if($.trim($("#thesauriWordCategoryId").val()).length<1) {
        	alert('请选择范畴！');
        	return null;
        }
		$.ajax({
			type : "post",
			url : "./thesauriWordAddEdit.do",
			data : {
				"id" : thesauriWordId,
				"wordName" : $("#wordName").val(),
				"isTopTerm" : $("#isTopTerm").val(),
				"wordPinyin" : $("#wordPinyin").val(),
				"wordEnglish": $("#wordEnglish").val(),
				"thesauriWordCategoryId" : $("#thesauriWordCategoryId").val(),
				"scopeNote" : $("#scopeNote").val(),
				"usageNote" : $("#usageNote").val(),
				"historicalNote" : $("#historicalNote").val(),
				"wordFormal" : $("#wordFormal").val(),
				"wordClasses" : $("#wordClasses").val(),
			},
			dataType : "json",
			async : true,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.tuxinghua(addwordClasses);
				window.parent.findAllthesauriWordReferenceLieBiao(relevanceCurr);
				window.parent.layer.msg('提交成功');
				parent.layer.close(index);
				
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
	var gongYongZiDuan;
	function getGongYongZiDuan(){
		return gongYongZiDuan;
	}
	var inputPId;
	function getInputPId(){
		return inputPId;
	}
	var inputPName;
	function getInputPName(){
		return inputPName;
	}
	var thesauriWordCategoryId;
	function getThesauriWordCategoryId(){
		return thesauriWordCategoryId;
	}
	function getclassesIds(){
		return $("#wordClasses").val();
	}
	//验证
	function verify(verifyName,verifyId){
		var regu="[\u4e00-\u9fa5]";
		var re = new RegExp(regu);
		if (re.test(verifyName)) {
	        alert("输入不符合规则，请重新输入！");
	        $("#"+verifyId).val("");
   		 }
	}
	function saveEditZTree() {
		gongYongZiDuan="叙词表(主题款目词表)";
		thesauriWordCategoryId =$("#thesauriWordCategoryId").val();
		inputPId="thesauriWordCategoryId";
		inputPName="thesauriWordCategoryName";
		parent.layer.open({
					type : 2,
					area : [ '650px', '600px' ],
					fix : false, //不固定
					//maxmin : true,
					scrollbar : false,
					shadeClose : true,
					title : '选择父节点',
					btn : [ '保存 ', '关闭' ],
					skin : 'layui-layer-rim', //加上边框
					content : ["word-thesauriWordCategoryAddEditFind-zTree.html?winName="+window.name,'no'],
					yes : function(index, layer) {
						//var iframeWin = window.parent.window[window.name].window['layui-layer-iframe'+ index];
						var iframeWin = parent.window[layer.find('iframe')[0]['name']];
						//alert(iframeWin);
						iframeWin.queren();
					},
					cancel : function(index) {
					}
				});
	};
	//关系
	function findEditThesauriWordReference() {
		$.getJSON(
				"./findAllthesauriWordReference.do",
				{
					thesauriWordId : thesauriWordId,
				},
				function(res) {
					var relation = $("#relation").val();
					if(relation != null && '' != relation){
						var relations = relation.split(";"); //字符分割 
						for (i=0;i<relations.length ;i++ ) { 
							$("#center_"+relations[i]).html("");
						} 
					}
					//此处仅仅是为了演示变化的内容
					for ( var i = 0; i < res.result[0].size; i++) {
						$("#center_"+res.result[i].referenceRelationLabel).append("<button type='button' class='btn btn-default btn-green btn-xs'  onclick=addEditThesauriWord('"
												+ res.result[i].referenceWordId+"','"+res.result[i].thesauriWordId+"','"+res.result[i].referenceRelationLabel+"') style='margin-top: 5px; margin-right: 5px;'>"
												+res.result[i].referenceWordName
												+"</button>");
					}
					if(relation != null && '' != relation){
						var relations = relation.split(";"); //字符分割 
						for (i=0;i<relations.length ;i++ ) { 
							$("#center_"+relations[i]).append("<button type='button' class='btn btn-default btn-blue btn-xs' onclick=wtFindReferenceSave('"+res.result[0].thesauriWordId+"','"+relations[i]+"') style='margin-top: 5px; margin-right: 5px;'>+</button>");
						} 
					}
				});	
						
		};
		var id;
		var twrId;
		
		function getThesauriWordId() {
			return id;
		}
		function getTwrId() {
			return twrId;
		}
		var source;
		function getsource() {
			return source;
		}
		function addEditThesauriWord(lid,tId,sources) {
			id = lid;
			twrId=tId;
			source=sources;
			var close_button='0';
			parent.layer.open({
				type : 2,
				area : [ '700px', '640px' ],
				scrollbar : false,
				shadeClose : true,
				fix : false, //不固定
				title : '主题款目词表',
				//maxmin : true,  
				skin : 'layui-layer-rim', //加上边框
				btn : ['保存','删除关联项', '关闭' ],
				content : [ "word-thesauriWord-addEdit.html?winName="+window.name, 'no' ],
				yes : function(index, layer) {
					var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					iframeWin.Page();
				},
				btn2 : function(index, layer) {
					close_button='1';
					var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					iframeWin.delThesauriWordReference();
				},
				cancel : function(index) {
					if(close_button=='0'){
							parent.layer.close(index);
						}
					return false;
				}
			});
		}
		function getShanChu(){
			return 1;
		}
		function addEditThesauriWord2(lid) {
		id = lid;
		parent.layer.open({
					type : 2,
					area : [ '700px', '640px' ],
					scrollbar : false,
					shadeClose : true,
					fix : false, //不固定
					title : '主题款目词表',
					//maxmin : true,  
					skin : 'layui-layer-rim', //加上边框
					btn : ['保存','关闭 '],
					content : [ "word-thesauriWord-addEdit.html?winName="+window.name, 'no' ],
					yes : function(index, layer) {
						var iframeWin = parent.window[layer.find('iframe')[0]['name']];
						iframeWin.Page();
					},
					cancel : function(index) {
					}
				});
	}
	function wtFindReferenceSave(thesauriWordId,source){
				parent.layer.open({
						type : 2,
						area : [ '900px', '600px' ],
						scrollbar : false,
						shadeClose : true,
						fix : false, //不固定
						title : '款目参照项',
						//maxmin : true,  
						skin : 'layui-layer-rim', //加上边框
						btn : [ '确认','关闭' ],
						content : [ "word-thesaurus-find-ReferenceSave.html?thesauriWordId="+thesauriWordId+"&source="+source+"&category=4&winName="+window.name+"&wordClasses="+addwordClasses, 'no' ],
						yes : function(index, layer) {
							 //var iframeWin = window.parent.window[window.name].window['layui-layer-iframe'+index];
							var iframeWin = parent.window[layer.find('iframe')[0]['name']];
							iframeWin.queRen();
						},
						cancel : function(index) {
						}
					});
		}
		
	
	function WordReferenceLieBiao(){
		var index = parent.layer.getFrameIndex(window.name);
		window.parent.findAllthesauriWordReferenceLieBiao(relevanceCurr);
		parent.layer.msg('关闭成功');
		parent.layer.close(index);
	}
	
	$('.js-tapbox>div').eq(0).show();
	var tapbox = $('.js-tapbox>div');
	$(document).on('click','.js-tapqh li a',function(){
		$(this).addClass('active').parent().siblings().find('a').removeClass('active');
		var idx = $(this).parent().index();
		tapbox.eq(idx).show().siblings().hide();
	});
	//层级
	var setting = {  
                data: {  
                    simpleData: {  
                        enable: true  
                    }  
                } ,
                async: {
                    enable: true,
                    url:"queryjunoirZTree.do",
                    autoParam:["id", "name", "level"],
                    otherParam:{"otherParam":"zTreeAsyncTest"},
                    dataFilter: filter
                }
        };  
        function filter(treeId, parentNode, childNodes) {
            if (!childNodes) return null;
            for (var i=0, l=childNodes.length; i<l; i++) {
                childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
            }
            return childNodes;
        }
        $(document).ready(function(){  
       		$.ajax({
				type : "post",
				url : "queryjunoirZTree.do",
				data : {
					"id" : thesauriWordId,
					"type":0
				},
				dataType : "json",
				success : function(data) {
				//alert(JSON.stringify(data));
				 $.fn.zTree.init($("#treeDemo"), setting, data); 
				},
				error : function(data) {
					alert("请求失败");
				}
			});
        });  
        function upWord(){
        	$.ajax({
				type : "post",
				url : "queryWpWord.do",
				data : {
					"id" : thesauriWordId,
				},
				dataType : "json",
				success : function(data) {
				 if(data[0].upWord != null && '' != data[0].upWord){
					 $("#upWord").show();
					 $("#upWord").html("上级："+data[0].upWord);
				 }
				},
				error : function(data) {
					alert("请求失败");
				}
			});
        }
</script>


